using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.Linq;

namespace Commons.Models.Settings.Dtos.Locks
{
	public class UnlockConditionsDto
	{
		[XmlElement(ElementName = "stats", Namespace = "http://www.ibeltran.com/schema/game/lock", Type = typeof(UserStatsUnlockConditionDto))]
		public List<UserStatsUnlockConditionDto> Stats;

		public List<IUnlockConditionDto> GetAllUnlockConditionDto()
		{
			if (allUnlockConditionDto != null)
			{
				return allUnlockConditionDto;
			}

			allUnlockConditionDto = new List<IUnlockConditionDto>();

			// append all IUnlockConditionDto to a single list
			AddRange<UserStatsUnlockConditionDto>(allUnlockConditionDto, Stats);
			return allUnlockConditionDto;
		}

		private static void AddRange<T>(List<IUnlockConditionDto> dest, List<T> src) where T:IUnlockConditionDto
		{
			if (src == null)
				return;

			dest.AddRange(src.Cast<IUnlockConditionDto>());
		}

		protected List<IUnlockConditionDto> allUnlockConditionDto;
	}
}

